package cn.stylefeng.guns.modular.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.service.IIdjFeedbackService;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * <p>
 * 反馈列表 前端控制器
 * </p>
 *
 * @author TANGWJ
 * @since 2020-08-25
 */
@Controller
@RequestMapping("/modular/feedback")
public class IdjFeedbackController {

	private static String PREFIX = "/feedback/";

	@Autowired
	private IIdjFeedbackService service;

	/**
	 * 跳转到用户的首页
	 */
	@RequestMapping
	public String index() {
		return PREFIX + "feedback.html";
	}

	@RequestMapping("details/{id}")
	public ModelAndView add(@PathVariable Long id) {
		ModelAndView index = service.edit(id);
		index.setViewName(PREFIX + "feedback_details.html");
		return index;
	}

	/**
	 * 列表
	 */
	@ResponseBody
	@GetMapping("list")
	public LayuiPageInfo list(String timeLimit, String keyword) {
		// 获取分页参数
		Page page = LayuiPageFactory.defaultPage();

		// 拼接查询条件
		String beginTime = null;
		String endTime = null;

		if (ToolUtil.isNotEmpty(timeLimit)) {
			String[] split = timeLimit.split(" - ");
			beginTime = split[0];
			endTime = split[1];
		}
		// 根据条件查询日志
		return service.getList(page, keyword, beginTime, endTime);
	}

}

